package com.service.impl;

import com.bean.User;
import com.dao.UserDao;
import com.dao.impl.UserDaoImpl;
import com.service.UserService;


public class UserServiceImpl implements UserService {
    //手动实现IOC 可以挑战
    UserDao userDao = new UserDaoImpl();
//修改密码
@Override
public int updateUserspasswords(User user) {
    //根据名字修改密码
    return userDao.updataUserpassword(user);
}
    //修改
    @Override
    public int updateUsers(User user) {
        return userDao.updataUser(user);
    }

    //注册用户
    @Override
    public int registUser(User user) {

        return userDao.saveUser(user);
    }

    //登录用户
    @Override
    public User login(User user) {
        return userDao.queryUserByUsernameAndPassword(user.getUserName(), user.getUserpassword());
    }

    /**
     * 名字查询信息
     * @param username
     * @return
     */
    @Override
    public User existsUsername(String username) {
        return userDao.queryUserByUsername(username);
    }

    //      查询名字判断用户是否存在
//    @Override
//    public boolean existsUsername(String username) {
//        return (userDao.queryUserByUsername(username) != null);
//    }

    //      通过名字邮箱注册判断
    @Override
    public boolean existsUsernameemail(String username, String useremail) {
        return (userDao.queryUserByUsernameemail(username, useremail) != null);
    }


    /**
     * 根据邮箱查询用户信息
     *
     * @param user
     * @return
     */
    @Override
    public User queryUseremail(User user) {
        return userDao.queryUserByUseremail(user.getUseremail());
    }
}
